package com.kc.sjwh.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.kc.sjwh.entity.po.App;
import com.kc.sjwh.other.Page;
import com.kc.sjwh.service.AppService;

/**
 * 应用管理action
 * @author zhangguihua(hua7381@163.com)
 * date: 2017年8月4日
 */
@Controller
@RequestMapping("app")
public class AppAction extends BaseAction {
	static Logger logger = Logger.getLogger(AppAction.class);
	
	@Autowired
	AppService service;
	

	//打开列表页面
	@RequestMapping("list")
	public String list(HttpServletRequest req) {
		return "app/appList";
	}

	//获取分页
	@ResponseBody
	@RequestMapping("getPage")
	public String getPage(HttpServletRequest req, int pageSize, int pageNum) {
		Page<App> page = service.getPage(pageSize, pageNum, super.getParamMap(req));
		return JSON.toJSONString(page);
	}

	//打开表单
	@RequestMapping("form")
	public String form(HttpServletRequest req, String act, String id) {
		req.setAttribute("act", act);
		req.setAttribute("id", id);
		req.setAttribute("actName", "add".equals(act)?"新增":"修改");
		return "app/appForm";
	}

	//表单加载
	@ResponseBody
	@RequestMapping("load4Update")
	public String load4Update(HttpServletRequest req, String id) throws Exception {
		App one = service.load4Update(id);
		return JSON.toJSONString(one);
	}

	//新增
	@ResponseBody
	@RequestMapping("add")
	public String add(HttpServletRequest req, App one) throws Exception {
		one.setCjrxm(getLoginUser().getMc());
		service.add(one);
		return JSON.toJSONString(null);
	}

	//修改
	@ResponseBody
	@RequestMapping("update")
	public String update(HttpServletRequest req, App one) throws Exception {
		service.update(one);
		return JSON.toJSONString(null);
	}

	//删除
	@ResponseBody
	@RequestMapping("delete")
	public String delete(HttpServletRequest req, String id) {
		service.delete(id);
		return JSON.toJSONString(null);
	}
}
